package com.wbk.controller;

import com.wbk.constant.MessageConstant;
import com.wbk.constant.RedisMessageConstant;
import com.wbk.entity.Result;
import com.wbk.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {

    @Autowired
    private JedisPool jedisPool;

    @RequestMapping("/send4Order")
    public Result send4Order(String telephone){
        Integer validateCode = ValidateCodeUtils.generateValidateCode(4);
        System.out.println("发送的验证码为："+validateCode);
        jedisPool.getResource().setex(telephone+ RedisMessageConstant.SENDTYPE_ORDER,5*60,String.valueOf(validateCode));
        return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
    }

    @RequestMapping("/send4Login")
    public Result send4Login(String telephone){
        Integer validateCode = ValidateCodeUtils.generateValidateCode(4);
        System.out.println("发送的验证码为："+validateCode);
        jedisPool.getResource().setex(telephone+ RedisMessageConstant.SENDTYPE_LOGIN,5*60,String.valueOf(validateCode));
        return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
    }
}
